﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Sdk.WeiXin.Domain
{

    /// <summary>
    /// 支付返回
    /// </summary>
    public class PayResponse
    {
        /// <summary>
        /// 商户端订单id
        /// </summary>
        public int Oid { get; set; } = 0;
        /// <summary>
        /// 商户端订单号
        /// </summary>
        public string OutTradeNo { get; set; } = string.Empty;
        /// <summary>
        /// 微信端交易号
        /// </summary>
        public string TransactionId { get; set; } = string.Empty;
        /// <summary>
        /// 付款总额(含优惠券金额)
        /// </summary>
        public decimal TotalFee { get; set; }
        /// <summary>
        /// 优惠券金额
        /// </summary>
        public decimal CouponFee { get; set; }
        /// <summary>
        /// 优惠券ID
        /// </summary>
        public string CouponIds { get; set; } = string.Empty;
        /// <summary>
        /// 是否服务商方式
        /// </summary>
        public bool IsProvider { get; set; } = false;
        /// <summary>
        /// 是否分账
        /// </summary>
        public bool IsProfit { get; set; } = false;
        /// <summary>
        /// 是否领取玖玖卡
        /// </summary>
        public bool IsRecieve { get; set; } = false;
        /// <summary>
        /// 支付用户openid
        /// </summary>
        public string OpenId { get; set; } = string.Empty;

        /// <summary>
        /// 交易状态: SUCCESS:支付成功, CLOSED:已关闭, REVOKED:已撤销(刷卡支付), USERPAYING:用户支付中, PAYERROR:支付失败(其他原因，如银行返回失败)
        /// </summary>
        public string TradeState { get; set; } = string.Empty;

        public static string GetErrorMsg(string errcode, string defMessage)
        {

            switch (errcode)
            {
                case "USERPAYING":return "用户支付中";
                case "NOTENOUGH": return "用户帐号余额不足";
                case "SYSTEMERROR": return "系统超时";
                case "PARAM_ERROR": return "支付确认失败,请求参数未按指引进行填写";
                case "ORDERPAID": return "支付确认失败,订单已支付";
                case "NOAUTH": return "商户无此接口权限";
                case "NOTSUPORTCARD": return "不支持卡类型";
                case "ORDERCLOSED": return "订单已关闭";
                case "ORDERREVERSED": return "订单已撤销";
                case "BANKERROR": return "银行系统异常";
                case "AUTH_CODE_ERROR": return "授权码参数错误";
                case "AUTH_CODE_INVALID": return "授权码检验错误";
                case "SIGNERROR": return "签名错误";
                case "OUT_TRADE_NO_USED": return "商户订单号重复";
                case "APPID_MCHID_NOT_MATCH": return "appid和mch_id不匹配";
                default: return defMessage;
            }
        }
    }

    /// <summary>
    /// 支付结果-营销详情
    /// </summary>
    public class PayPromotion
    {
        public List<PayPromotionDetail> promotion_detail { get; set; }
    }
    /// <summary>
    /// 支付结果-优惠活动详情
    /// </summary>
    public class PayPromotionDetail
    {
        /// <summary>
        /// 券或者立减优惠id
        /// </summary>
        public string promotion_id { set; get; }
        /// <summary>
        /// 优惠名称
        /// </summary>
        public string name { set; get; }
        /// <summary>
        /// GLOBAL 全场代金券, SINGLE 单品优惠
        /// </summary>
        public string scope { get; set; }
        /// <summary>
        /// 优惠类型(COUPON 代金券,DISCOUNT 优惠券)
        /// </summary>
        public string type { get; set; }
        /// <summary>
        /// 用户享受优惠的金额
        /// </summary>
        public int amount { get; set; }
        /// <summary>
        /// 微信商户后台配置的批次ID
        /// </summary>
        public string activity_id { get; set; }
    }
}